﻿using Microsoft.Extensions.DependencyInjection;
using System;
using Volo.Abp.Domain.Services;
using Xms.Abp.Linq;
using Xms.Abp.ObjectMapping;

namespace Xms.Abp.Domain;

public abstract class XmsDomainService : DomainService, IXmsDomainService
{
    private IQueryableExecuter _QueryableExecuter;
    protected IQueryableExecuter QueryableExecuter
    {
        get
        {
            if (_QueryableExecuter == null)
            {
                _QueryableExecuter = AsyncExecuter as IQueryableExecuter;
                if (_QueryableExecuter == null)
                {
                    _QueryableExecuter = LazyInject<IQueryableExecuter>();
                }
            }
            return _QueryableExecuter;
        }
    }
    protected IXmsObjectMapper ObjectMapper => LazyInject<IXmsObjectMapper>();
    public TService LazyInject<TService>()
    {
        return LazyServiceProvider.LazyGetRequiredService<TService>();
    }

    [Obsolete("Use LazyInject method.")]
    protected TService Inject<TService>()
    {
        return ServiceProvider.GetRequiredService<TService>();
    }
}
